package com.comprehensive.dataservice.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyBatisPlusConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 创建分页插件实例，指定数据库类型为 MySQL
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
        // 设置分页溢出处理，当页码超过最大页时返回最后一页数据
        paginationInnerInterceptor.setOverflow(false);
        // 设置单页最大记录数限制为 100
        paginationInnerInterceptor.setMaxLimit(100L);
        // 将分页插件添加到 MyBatis-Plus 拦截器链中
        interceptor.addInnerInterceptor(paginationInnerInterceptor);
        return interceptor;
    }
}